import matplotlib.pyplot as plt
"""有意思的是下面的中文显示方法在绘制折线图时表现正常，而在绘制散点图时仍旧会报错，无法显示中文"""
from pylab import mpl
# 设置显示中文字体
mpl.rcParams["font.sans-serif"] = ["SimHei"]
# 设置正常显示符号
mpl.rcParams["axes.unicode_minus"] = False

# 15-1/15-2
# x_value = range(1,5001)
# y_value = [x**3 for x in x_value]
#
# plt.style.use('seaborn-v0_8')
# # squares = [1,4,9,16,25]
# fig,ax = plt.subplots()
# # ax.plot(squares,linewidth=3)
# ax.scatter(x_value,y_value,c=y_value,cmap=plt.cm.Blues,s=10)
#
# # 设置图表标题并给坐标轴加上标签
# ax.set_title("立方值",fontsize=14)
# ax.set_xlabel("值",fontsize=14)
# ax.set_ylabel("值的立方",fontsize=14)
#
# # 设置每个坐标轴的取值范围
# ax.axis([0,5100,0,125000000000])
#
# plt.show()

# 15-3
# from random_walk import RandomWalk
#
# # 创建一个RandomWalk实例
# rw = RandomWalk()
# rw.fill_walk()
# # 将所有点都绘制出来
# plt.style.use('classic')
# fig,ax = plt.subplots()
# ax.plot(rw.x_values,rw.y_values,linewidth=2)
# plt.show()

# 15-4
# from random_walk import RandomWalk
#
# # 创建一个RandomWalk实例
# rw = RandomWalk()
# rw.fill_walk()
# # 将所有点都绘制出来
# plt.style.use('classic')
# fig,ax = plt.subplots()
# ax.scatter(rw.x_values,rw.y_values,s=15)
# plt.show()

# 15-5
# 详情见模块RandomWalk

# 15-6
# from plotly.graph_objs import Bar,Layout
# from plotly import offline
#
# from die import Die
#
# # Create two D8 dice.
# die_1 = Die(8)
# die_2 = Die(8)
#
# # Make some rolls, and store results in a list.
# results = []
# for roll_num in range(1000):
#     result = die_1.roll() + die_2.roll()
#     results.append(result)
#
# # Analyze the results.
# frequencies = []
# max_result = die_1.num_sides + die_2.num_sides
# for value in range(2, max_result + 1):
#     frequency = results.count(value)
#     frequencies.append(frequency)
#
# # Visualize the results.
# x_values = list(range(2,max_result+1))
# data = [Bar(x=x_values,y=frequencies)]
#
# x_axis_config = {'title':'结果','dtick':1}
# y_axis_config = {'title':'结果的频率'}
# my_layout = Layout(title='掷两个D8 1000次的结果',xaxis=x_axis_config,yaxis=y_axis_config)
# offline.plot({'data':data,'layout':my_layout},filename='d8_d8.html')

# 15-7
# from plotly.graph_objs import Bar,Layout
# from plotly import offline
#
# from die import Die
#
# # Create three D6 dice.
# die_1 = Die()
# die_2 = Die()
# die_3 = Die()
#
# # Make some rolls, and store results in a list.
# results = []
# for roll_num in range(1000):
#     result = die_1.roll() + die_2.roll() + die_3.roll()
#     results.append(result)
#
# # Analyze the results.
# frequencies = []
# max_result = die_1.num_sides + die_2.num_sides + die_3.num_sides
# for value in range(3, max_result + 1):
#     frequency = results.count(value)
#     frequencies.append(frequency)
#
# # Visualize the results.
# x_values = list(range(3,max_result+1))
# data = [Bar(x=x_values,y=frequencies)]
#
# x_axis_config = {'title':'结果','dtick':1}
# y_axis_config = {'title':'结果的频率'}
# my_layout = Layout(title='掷三个D6 1000次的结果',xaxis=x_axis_config,yaxis=y_axis_config)
# offline.plot({'data':data,'layout':my_layout},filename='d6_d6_d6.html')

# 15-8/15-9
# from plotly.graph_objs import Bar,Layout
# from plotly import offline
#
# from die import Die
#
# # Create two D6 dice.
# die_1 = Die()
# die_2 = Die()
#
# # Make some rolls, and store results in a list.
# results = [die_1.roll() * die_2.roll() for roll_num in range(1000)]
#
# # Analyze the results.
# frequencies = []
# max_result = die_1.num_sides * die_2.num_sides
# for value in range(1, max_result + 1):
#     frequency = results.count(value)
#     frequencies.append(frequency)
#
# # Visualize the results.
# x_values = list(range(1,max_result+1))
# data = [Bar(x=x_values,y=frequencies)]
#
# x_axis_config = {'title':'结果','dtick':1}
# y_axis_config = {'title':'结果的频率'}
# my_layout = Layout(title='掷两个D6 1000次的结果',xaxis=x_axis_config,yaxis=y_axis_config)
# offline.plot({'data':data,'layout':my_layout},filename='d6_d6.html')

# 16-1
# import csv
# from datetime import datetime
#
# from matplotlib import pyplot as plt
#
# filename = 'death_valley_2018_simple.csv'
# with open(filename) as f:
#     reader = csv.reader(f)
#     header_row = next(reader)
#
#     # Get dates and high temperatures from this file.
#     dates, precipitations = [], []
#     for row in reader:
#         current_date = datetime.strptime(row[2], '%Y-%m-%d')
#         dates.append(current_date)
#         precipitation = float(row[3])
#         precipitations.append(precipitation)
#
# # Plot the high temperatures.
# # plt.style.use('seaborn')
# fig, ax = plt.subplots()
# ax.plot(dates, precipitations, c='red')
#
# # Format plot.
# plt.title("Daily precipitations - 2018", fontsize=24)
# plt.xlabel('', fontsize=16)
# fig.autofmt_xdate()
# plt.ylabel("Precipitation (mm)", fontsize=16)
# plt.tick_params(axis='both', which='major', labelsize=16)
#
# plt.show()

# 16-2
# import csv
# from datetime import datetime
#
# from matplotlib import pyplot as plt
#
# filename = 'sitka_weather_2018_simple.csv'
# with open(filename) as f:
#     reader = csv.reader(f)
#     header_row = next(reader)
#
#     # Get dates, and high and low temperatures from this file.
#     dates, highs, lows = [], [], []
#     for row in reader:
#         current_date = datetime.strptime(row[2], '%Y-%m-%d')
#         high = int(row[5])
#         low = int(row[6])
#         dates.append(current_date)
#         highs.append(high)
#         lows.append(low)
#
# # Plot the high and low temperatures.
# # plt.style.use('seaborn')
# fig, ax = plt.subplots()
# ax.plot(dates, highs, c='red', alpha=0.5)
# ax.plot(dates, lows, c='blue', alpha=0.5)
# plt.fill_between(dates, highs, lows, facecolor='blue', alpha=0.1)
#
# # Format plot.
# plt.title("Daily high and low temperatures - 2018", fontsize=24)
# plt.xlabel('', fontsize=16)
# fig.autofmt_xdate()
# plt.ylabel("Temperature (F)", fontsize=16)
# plt.yticks(list(range(20,140,10)))
# plt.tick_params(axis='both', which='major', labelsize=16)
#
# plt.show()

# 16-4
# import csv
# from datetime import datetime
#
# from matplotlib import pyplot as plt
#
# filename = 'death_valley_2018_simple.csv'
# with open(filename) as f:
#     reader = csv.reader(f)
#     header_row = next(reader)
#     index_TMAX = header_row.index('TMAX')
#     index_TMIN = header_row.index('TMIN')
#
#     # Get dates, and high and low temperatures from this file.
#     dates, highs, lows = [], [], []
#     for row in reader:
#         current_date = datetime.strptime(row[2], '%Y-%m-%d')
#         high = int(row[index_TMAX])
#         low = int(row[index_TMIN])
#         dates.append(current_date)
#         highs.append(high)
#         lows.append(low)
#
# # Plot the high and low temperatures.
# # plt.style.use('seaborn')
# fig, ax = plt.subplots()
# ax.plot(dates, highs, c='red', alpha=0.5)
# ax.plot(dates, lows, c='blue', alpha=0.5)
# plt.fill_between(dates, highs, lows, facecolor='blue', alpha=0.1)
#
# # Format plot.
# plt.title("Daily high and low temperatures - 2018", fontsize=24)
# plt.xlabel('', fontsize=16)
# fig.autofmt_xdate()
# plt.ylabel("Temperature (F)", fontsize=16)
# plt.yticks(list(range(20,140,10)))
# plt.tick_params(axis='both', which='major', labelsize=16)
#
# plt.show()
